package com.microstrategy.database.hbase.control;

import java.util.List;

import org.apache.hadoop.conf.Configuration;

import com.microstrategy.database.hbase.datasource.AdminDataSource;
import com.microstrategy.database.hbase.model.RegionOfTableOnEachRSServer;

public class FetchAdmindataRunnable implements Runnable {

	AdminDataSource asource;
	int pause = 30 * 1000;

	public FetchAdmindataRunnable(String zk, int port) {
		Configuration configuration = new Configuration();
		configuration.set("hbase.zookeeper.quorum", zk);
		configuration.set("hbase.zookeeper.property.clientPort", port + "");
		asource = new AdminDataSource(configuration);
	}

	public void setPause(int t) {
		this.pause = t;
	}

	@Override
	public void run() {
		while (true) {
			List<RegionOfTableOnEachRSServer> ls = asource.getRTRS();
			for (RegionOfTableOnEachRSServer l : ls) {
				l.Save();
			}
			try {
				Thread.sleep(pause);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
